package com.example.firstandroidonosc;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

	private TextView tips;
	private EditText content;
	private Button commit;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// init
		tips = (TextView) findViewById(R.id.tips);
		content = (EditText) findViewById(R.id.content);
		commit = (Button) findViewById(R.id.commit);

		commit.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.commit:

			// 获取输入内容
			String inputVal = content.getText().toString();
			Log.d("FirstAndroidOnOsc", "---->" + inputVal);

			new AlertDialog.Builder(MainActivity.this)
					.setTitle("友情提示")
					.setMessage("您输入的内容为：" + inputVal + "。")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							content.setText("");
						}
					})
					.setNegativeButton("取消继续输入", new DialogInterface.OnClickListener() {
						
						@Override
						public void onClick(DialogInterface dialog, int which) {
							
						}
					})
					.setCancelable(false)
					.create().show();

			break;

		default:
			break;
		}
	}
}
